package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.AttachmentPolicyModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by sxy on 2016/7/13.
 */
public interface AttachmentPolicyRepository extends JpaRepository<AttachmentPolicyModel, Integer>, JpaSpecificationExecutor<AttachmentPolicyModel> {

    @Modifying
    @Query("update AttachmentPolicyModel u set u.siStatus = ?3 where u.siProgramCodeEnglish = ?1 and u.siTypeDescription = ?2")
    int setSiStatusBySiProgramCodeEnglishAndSiTypeDescription(String siProgramCodeEnglish, String siTypeDescription, String status);
    
    @Query("select u from AttachmentPolicyModel u where u.siProgramCodeEnglish = ?1 and u.permit = ?2")
    List<AttachmentPolicyModel> findPolicyBYSiProgramCodeEnglishAndPermit(String siProgramCodeEnglish,String permit);
    
    @Modifying
    @Query("delete from AttachmentPolicyModel u where u.itemNumber = ?1 and u.permit = ?2 and u.siProgramCodeEnglish =?3")
    int deleteByItemNumAndPermit(Integer itemNumber,String permit,String siCode);
    
    @Modifying
    @Query("delete from AttachmentPolicyModel u where u.siProgramCodeEnglish = ?1 and u.permit = ?2")
    int deleteByProCodeEngAndPermit(String proCodeEng,String permit);
    
    @Modifying
    @Query("delete from AttachmentPolicyModel u where u.siProgramCodeEnglish = ?1 and u.itemNumber = ?2")
    int deleteByProCodeEngAndItemNo(String proCodeEng,Integer itemNo);
}
